package 课后作业1.Test2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test {
    static List<Employee> employeeList = new ArrayList<>();

    static {
        employeeList.add(new Employee(1, "张三", 18, 3000));
        employeeList.add(new Employee(2, "李四", 25, 3500));
        employeeList.add(new Employee(3, "王五", 2, 3200));
    }

    public static void main(String[] args) {
        System.out.println("工号\t姓名\t年龄\t工资");
        for (Employee e : employeeList) {
            System.out.println(e.getEmployeeNum() + "\t" + e.getName() + "\t" + e.getAge() + "\t" + e.getSalary());
        }
        //插入
        employeeList.add(1, new Employee(4, "赵六", 24, 3300));
        System.out.println("工号\t姓名\t年龄\t工资");
        for (Employee e : employeeList) {
            System.out.println(e.getEmployeeNum() + "\t" + e.getName() + "\t" + e.getAge() + "\t" + e.getSalary());
        }
        //删除
        for (Employee e : employeeList) {
            if ("王五".equals(e.getName())) {
                employeeList.remove(e);
                break;
            }
        }
        System.out.println("工号\t姓名\t年龄\t工资");
        for (Employee e : employeeList) {
            System.out.println(e.getEmployeeNum() + "\t" + e.getName() + "\t" + e.getAge() + "\t" + e.getSalary());
        }
        //迭代
        Iterator<Employee> iterator = employeeList.iterator();
        System.out.println("工号\t姓名\t年龄\t工资");
        while (iterator.hasNext()) {
            Employee employee = iterator.next();
            System.out.println(employee.getEmployeeNum() + "\t" + employee.getName() + "\t" + employee.getAge() + "\t" + employee.getSalary());
        }


    }
}